<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */


class RedCross_Filter_HtmlPurifier implements Zend_Filter_Interface
{

    protected $_instance = null;

    public function __construct($options = null)
    {
    	if (!class_exists('HTMLPurifier_Bootstrap', false)) {
            require_once 'HTMLPurifier/Bootstrap.php';
            spl_autoload_register(array('HTMLPurifier_Bootstrap', 'autoload'));
    	}

        $config = HTMLPurifier_Config::createDefault();
        $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
        $config->set('Cache.SerializerPath', APPLICATION_PATH . '/../data/cache/htmlpurifier');

        if (!is_null($options)) {
        	foreach ($options as $key => $value) {
        		$config->set($key, $value);
        	}
        }
        $this->_instance = new HTMLPurifier($config);
    }

    public function filter($value)
    {
        return $this->_instance->purify($value);
    }

}